<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>分单对账</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
                <span>分单号:</span><input id="keyBillCode" name="keyBillCode" emptyText="请输入分单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="分单号不能为空" />
                <span class="separator"></span>
                <span>运输种类:</span><input id="keyTransportSpeciesId" name="keyTransportSpeciesId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择运输种类" onvaluechanged="transportSpeciesIdChange" />
                <span class="separator"></span>
                <span>承运方式:</span><input id="keyTransportWayId" name="keyTransportWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择承运方式"/>

                <span class="separator"></span>
                <span>发货人:</span>
                <div id="keyDeliveryCustomerId" name="keyDeliveryCustomerId" class="mini-autocomplete" style="width:250px;"  popupWidth="1000" textField="name" valueField="id"
                     url="${base}/pages/customer_manage/queryDeliveryCustomerByKey"  required="false" requiredErrorText="发货人不能为空"
                     searchField="key"
                     emptyText="发货人名称">
                    <div property="columns">
                        <div header="ID" field="id" width="30"></div>
                        <div header="客户名称" field="name"></div>
                        <div header="客户简称" field="shortName"></div>
                        <div header="客户电话" field="phone"></div>
                        <div header="客户地址" field="address"></div>
                    </div>
                </div>

                <span class="separator"></span>
                <span>分单归属部门:</span>
                <input id="keyAttributionDepartmentId" name="keyAttributionDepartmentId" class="mini-treeselect" style="width:250px;" textField="name" valueField="id" emptyText="请选择..."
                       expandOnLoad="2"  virtualScroll="true"
                       required="false" allowInput="true" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择归属部门"/>

                <div style="margin-top: 5px"></div>
                <span>提货点:</span>
                <div id="keyPickUpPointId" name="keyPickUpPointId" class="mini-autocomplete" style="width:150px;"  popupWidth="500" textField="name" valueField="id"
                     required="false" requiredErrorText="提货点不能为空"
                     url="${base}/pages/basic_data_manage/xt_pick_up_point/queryPickUpPointByCondition?cityId="
                     searchField="key"
                     emptyText="提货点名称">
                    <div property="columns">
                        <div header="提货点名称" field="name" width="150"></div>
                        <div header="提货点电话" field="phone" width="150"></div>
                        <div header="提货点地址" field="address" width="200"></div>
                    </div>
                </div>

                <span class="separator"></span>
                <span>提货方式:</span>
                <input id="keyPickUpGoodsWayId" name="keyPickUpGoodsWayId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择提货方式"/>

                <span class="separator"></span>
                <span>开单日期：</span>
                <input id="keyOpenBillStartDate" name="keyOpenBillStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>--<input id="keyOpenBillEndDate" name="keyOpenBillEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>

                <span>代理送货费结费状态:</span>
                <input id="keyAgentDeliveryChargeStatusId" name="keyAgentDeliveryChargeStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择代理送货费结费状态"/>
                <span class="separator"></span>
                <span>分单对账状态:</span>
                <input id="keyAccountCheckStatusId" name="keyAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择分单对账状态"/>

                <span class="separator"></span>
                <span>代理送货费对账状态:</span>
                <input id="keyAgentDeliveryChargeAccountCheckStatusId" name="keyAgentDeliveryChargeAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择代理送货费对账状态"/>

                <div style="margin-top: 5px"></div>

                <span>发货人付款方式:</span>
                <input id="keyDeliveryCustomerPaymentMethodId" name="keyDdeliveryCustomerPaymentMethodId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                            required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择发货人付款方式" />
                <span class="separator"></span>

                <span>收货人付款方式:</span>
                <input id="keyReceiveCustomerPaymentMethodId" name="keyReceiveCustomerPaymentMethodId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                            required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择收货人付款方式" />



                <div style="margin-top: 5px"></div>
                <% if(so.hasPermission("nativeBillReconciliation:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="searchBill()">查询</a>
                <% } %>

                <% if(so.hasPermission("nativeBillReconciliation:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>


                <span class="separator"></span>

                <% if(so.hasPermission("nativeBillReconciliation:confirm")){%>
                    <a class="mini-button" iconCls="icon-lock" onclick="accountStatusChange(432)">分单确认对账</a>
                <% } %>

                <% if(so.hasPermission("nativeBillReconciliation:cancel")){%>
                    <a class="mini-button" iconCls="icon-unlock" onclick="accountStatusChange(431)">分单取消对账</a>
                <% } %>

                <% if(so.hasPermission("nativeBillReconciliation:confirmAgentDeliveryCharge")){%>
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-lock" onclick="agentDeliveryChargeAccountCheckStatus(432)">代理送货费确认对账</a>
                    <a class="mini-button" iconCls="icon-lock" onclick="showAccountPanel()">代理送货费导入对账</a>
                    <a href="${base!}/hymj/files/分单代理送货费对账模板.rar" target="_blank">点击下载《分单代理送货费对账》模板</a>
                    <a class="mini-button" iconCls="icon-unlock" onclick="agentDeliveryChargeAccountCheckStatus(431)">代理送货费取消对账</a>
                <%}%>

                <span class="separator"></span>

                <% if(so.hasPermission("nativeBillReconciliation:download")){%>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="提货点对账表"/>
                <% } %>

                <div style="margin-top: 5px"></div>
                <span style="color: red;"><span style="color: #0E2D5F">确认对账分单状态要求:</span>分单配载状态->全部配载，分单作废状态->未作废</span>
                <span style="color: red;margin-left: 40px"><span style="color: #0E2D5F">取消对账分单状态要求:</span>分单结算状态->未结算</span>


            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/finance_manage/reconciliation/queryPickUpNatvieBillReconciliationList" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 multiSelect = "true" allowResize="true"
                 showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                 allowSortColumn = "true"
                 sortField="createTime"
                 sortOrder="desc"
                 ondrawsummarycell="summaryRight"
            >
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div field="accountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">对账状态</div>

                    <div field="agentDeliveryChargeAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">代理送货费对账状态</div>

                    <div field="openBillDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">开单日期</div>
                    <div field="id" width="140" headerAlign="center" align="center" allowSort="true" renderer="showNativeBillRender">分单号</div>
                    <div field="billLoadMasterBillIds" width="140" headerAlign="center" align="left" allowSort="true" >主单号</div>
                    <div field="flightName" width="140" headerAlign="center" align="center" allowSort="true">班次号</div>
                    <div field="pickUpPointName" width="140" headerAlign="center" align="center" allowSort="true">提货点</div>
                    <div field="pickUpGoodsWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">提货方式</div>
                    <div field="receiveCustomerName" width="140" headerAlign="center" align="center" allowSort="true">收货人</div>
                    <div field="totalNumber" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">总件数</div>
                    <div field="actualWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">实重</div>
                    <div field="chargeableWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">计重</div>
                    <div field="goodsName" width="140" headerAlign="center" align="center" allowSort="true" >货物名称</div>
                    <div field="openBillDeliveryCharge" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">开单送货费</div>
                    <div field="agentDeliveryCharge" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">代理送货费</div>
                    <div field="collectionMoney" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">代收款</div>


                    <div field="attributionDepartmentId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"department"}' renderer="commonRender">归属部门</div>
                    <div field="signChooseId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">签收方式</div>
                    <div field="agentDeliveryChargeStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">代理送货费状态</div>
                    <div field="cancelStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">作废状态</div>
                    <div field="billLoadStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">配载状态</div>
                    <div field="settlementStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">结算状态</div>
                    <div field="openBillUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">开单人</div>
                    <div field="openBillDepartmentId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"department"}' renderer="commonRender">开单部门</div>
                    <div field="transportWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">承运方式</div>
                    <div field="destCityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">目的市</div>
                    <div field="deliveryCustomerSalemanId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysUser"}' renderer="commonRender">发货客户业务员</div>
                    <div field="airportId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airport"}' renderer="commonRender">始发机场</div>
                    <div field="flightDate" width="140" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd" renderer="ondayRenderer">班次日期</div>
                    <div field="airlinesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airlines"}' renderer="commonRender">航空公司</div>
                    <div field="planTakeOffTime" width="140" headerAlign="center" align="center" allowSort="true">计划出发时间</div>
                    <div field="volumeInformation" width="140" headerAlign="center" align="center" allowSort="true">体积信息</div>
                    <div field="weightRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">重量费率</div>
                    <div field="volume" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">体积</div>
                    <div field="volumeRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">体积费率</div>
                    <div field="transportCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">运费合计</div>
                    <div field="declaredValue" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">声明价值</div>
                    <div field="insuranceRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" >保费费率</div>
                    <div field="insuranceFee" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">保费</div>
                    <div field="otherCharges" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">其他费用</div>
                    <div field="deliveryCustomerPaymentMethodId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">发货人付款方式</div>
                    <div field="deliveryCustomerPaymentAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">发货人付款金额</div>
                    <div field="receiveCustomerPaymentMethodId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">收货人付款方式</div>
                    <div field="receiveCustomerPaymentAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">收货人付款金额</div>
                    <div field="otherChargesComment" width="140" headerAlign="center" align="center" allowSort="false">其他费用说明</div>
                    <div field="comment" width="140" headerAlign="center" align="center" allowSort="false">备注</div>
                </div>
            </div>
        </div>


        <!-- 对账数据上传 -->
        <div id="accountPanel" class="mini-window" title="对账数据上传" style="width:800px;height:600px;"
             showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
             showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true" >
            <div property="footer" style="padding:10px;text-align: right">
                <a  id="uploadBtn" name="uploadBtn" class="mini-button" iconCls="icon-upload" onclick="uploadAccount()">上传并对账</a>
                <a  class="mini-button" iconCls="icon-close" onclick="public_onCancel('accountPanel')">关闭</a>
            </div>


            <span id="fileTitle">代理送货费对账文件:</span>
            <form id="upload-form-add" style="display: inline">
                <input type="file" id="upLoadAccountFileData" name="upLoadFileData"  accept=".xls,.xlsx" />
            </form>


            <div style="height: 5px"></div>
            <span>对账结果:</span>
            <div style="height: 5px"></div>
            <div id="accountResult" style="color: red">

            </div>

        </div>


        <script type="text/javascript">
            mini.parse();

            let keyBillCode = mini.get("keyBillCode");
            let keyTransportSpeciesId = mini.get("keyTransportSpeciesId");
            let keyTransportWayId = mini.get("keyTransportWayId");
            let keyDeliveryCustomerId = mini.get("keyDeliveryCustomerId");
            let keyAttributionDepartmentId = mini.get("keyAttributionDepartmentId");
            let keyPickUpPointId = mini.get("keyPickUpPointId");
            let keyPickUpGoodsWayId = mini.get("keyPickUpGoodsWayId");
            let keyOpenBillStartDate = mini.get("keyOpenBillStartDate");
            let keyOpenBillEndDate = mini.get("keyOpenBillEndDate");
            let keyAgentDeliveryChargeStatusId = mini.get("keyAgentDeliveryChargeStatusId");
            let keyAccountCheckStatusId = mini.get("keyAccountCheckStatusId");
            let keyDeliveryCustomerPaymentMethodId = mini.get("keyDeliveryCustomerPaymentMethodId");
            let keyReceiveCustomerPaymentMethodId = mini.get("keyReceiveCustomerPaymentMethodId");


            let grid = mini.get("datagrid1");


            let accountResult = document.getElementById("accountResult");

            $(function () {
                // 运输种类下拉列表
                let transportSpeciesIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_TRANSPORT_SPECIES");
                keyTransportSpeciesId.load(transportSpeciesIdJsonData);

                // 承运方式下拉列表
                let transportWayIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_TRANSPORT_WAY");
                keyTransportWayId.load(transportWayIdJsonData);

                // 提货方式下拉列表
                let pickUpGoodsWayIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_PICK_UP_GOODS_WAY");
                keyPickUpGoodsWayId.load(pickUpGoodsWayIdJsonData);

                // 部门下拉列表
                let keyAttributionDepartmentIdJsonData = commonRenderDropList("department");
                keyAttributionDepartmentId.loadList(keyAttributionDepartmentIdJsonData,"id","pid");

                // 结费状态
                let keyAgentDeliveryChargeStatusIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_SETTLEMENT_STATUS");
                keyAgentDeliveryChargeStatusId.load(keyAgentDeliveryChargeStatusIdJsonData);

                // 对账状态
                let keyAccountCheckStatusIdJsonDate  = commonRenderSysDicDropListByKey("sysDic","XT_DIC_ACCOUNT_CHECK_STATUS");
                keyAccountCheckStatusId.load(keyAccountCheckStatusIdJsonDate);

                // 发货人付款方式
                let keyDeliveryCustomerPaymentMethodIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_DELIVERY_CUSTOMER_PAYMENT_METHOD");
                keyDeliveryCustomerPaymentMethodId.load(keyDeliveryCustomerPaymentMethodIdJsonData);

                // 收货人付款方式
                let keyReceiveCustomerPaymentMethodIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_RECEIVE_CUSTOMER_PAYMENT_METHOD");
                keyReceiveCustomerPaymentMethodId.load(keyReceiveCustomerPaymentMethodIdJsonData);

                clearSearch()

                // 加载列表数据
                grid.load();
            });

            /**
             * 清空查询条件
             */
            function clearSearch(){
                let form = new mini.Form("#queryForm");
                form.clear();
            }

            let cancelStatus = {notCanceled:411, canceled:412}

            /**
             * 根据查询条件查询分单
             * 410,0,作废状态,作废状态,XT_DIC_CANCEL_STATUS
             411,410,未作废,未作废,
             412,410,已作废,已作废,
             */
            function searchBill(){
                let form = new mini.Form("#queryForm");
                let data = form.getData(true);
                // 一定是未作废的单子
                data.keyCancelStatusId = cancelStatus.notCanceled;
                grid.load(data);
            }

            function showNativeBillRender(e){
                //  renderer="showNativeBillRender"
                let nativeBillId = e.value;
                let htmlStr = "<a href='javascript:void(0);' onclick='showViewNativeBill(\""+ nativeBillId +"\")'>" + nativeBillId + "</a>";
                return htmlStr;
            }

            function showViewNativeBill(nativeBillId){
                let tabUrl="${base}/pages/native_bill_manage/showUpdateBill?opType=view&id=" + nativeBillId;
                parent.window.addTabToMainPage("分单查看","分单查看",tabUrl);
            }

            /**
             *
             * 根据选择的分单作废分单
             *
             * 410,0,作废状态,作废状态,XT_DIC_CANCEL_STATUS
             * 411,410,未作废,未作废,
             * 412,410,已作废,已作废,

             * 350,0,分单配载状态,分单配载状态,XT_DIC_BILL_LOAD_STATUS
             * NO_LOAD(351, "未配载", "未配载"),
             * PART_LOAD(352, "部分配载", "部分配载"),
             * ALL_LOAD(353, "全部配载", "全部配载");

             * 320,0,结算状态,结算状态,XT_DIC_SETTLEMENT_STATUS
             * 321,320,未结算,未结算,""
             * 322,320,已结算,已结算,""
             *
             *
             * 430,0,分单主单对账状态,分单主单对账状态,XT_DIC_ACCOUNT_CHECK_STATUS
             * 431,430,未对账,未对账,
             * 432,430,已对账,已对账,

             */

            let loadStatus = {noLoad:351, partLoad:352, allLoad:353};

            let settlementStatus = {uncleared:321, cleared:322};

            let accountCheckStatus = {noCheck:431, checked:432};


            function accountStatusChange(accountStatus){
                let selectItems = grid.getSelecteds();
                if(selectItems.length==0){
                    showAlert("请选择需要改变对账状态的分单!");
                    return;
                }

                // 前端过滤，对已经完成配载且没有对账没有结算的分单进行对账状态修改
                // 需要注意的如果是已经结算过的分单是不能进行对账取消的
                let canAccountCheckIds = "";
                let canNotAccountCheckIds = "";

                if(accountStatus == accountCheckStatus.checked){
                    for(let obj of selectItems){
                        if(obj.billLoadStatusId != loadStatus.allLoad || obj.cancelStatusId == cancelStatus.canceled){
                            canNotAccountCheckIds += obj.id + " ";
                        }
                        else{
                            canAccountCheckIds += "'" + obj.id + "',";
                        }
                    }
                }
                else{
                    for(let obj of selectItems){
                        if(obj.settlementStatusId == settlementStatus.cleared){
                            canNotAccountCheckIds += obj.id + " ";
                        }
                        else{
                            canAccountCheckIds += "'" + obj.id + "',";
                        }
                    }
                }

                if(canNotAccountCheckIds.length>0){
                    canNotAccountCheckIds = canNotAccountCheckIds.substring(0,canNotAccountCheckIds.length-1);
                    if(accountStatus == accountCheckStatus.checked){
                        showAlert("选择的对账分单【" + canNotAccountCheckIds + "】没有全部配载或已经作废，不能进行对账确认操作!");
                    }
                    else{
                        showAlert("选择的对账分单【" + canNotAccountCheckIds + "】已结算，不能进行对账取消操作!");
                    }
                    return;
                }

                let title = accountStatus == accountCheckStatus.checked?"确认对账?":"取消对账?";
                canAccountCheckIds = canAccountCheckIds.substring(0,canAccountCheckIds.length-1);
                // 给出确认提示框
                mini.confirm("确定为分单【" + canAccountCheckIds + "】"+ title, "对账提示",
                    function (action) {
                        if (action == "ok") {
                            let ret = public_getServerData("${base}/pages/native_bill_manage/changeAccountCheckStatus",{billIds:canAccountCheckIds,accountCheckStatusId:accountStatus});
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    grid.reload();
                                }
                            });
                        }
                    }
                );
            }


            /**
             * 设置底部统计样式
             * @param e
             */
            function summaryRight(e){
                e.cellStyle="text-align:right;color:red;font-size:18px;font-weight:bold";
            }


            /**
             * 分单代理送货费对账取消或确认
             */
            function agentDeliveryChargeAccountCheckStatus(accountStatus){
                let selectItems = grid.getSelecteds();
                if(selectItems.length==0){
                    showAlert("请选择需要改变代理送货费对账状态的分单!");
                    return;
                }

                // 前端过滤，对已经完成配载且没有对账没有结算的分单进行对账状态修改
                // 需要注意的如果是已经结算过的分单是不能进行对账取消的
                let canAccountCheckIds = "";
                let canNotAccountCheckIds = "";

                if(accountStatus == accountCheckStatus.checked){
                    for(let obj of selectItems){
                        if(obj.billLoadStatusId != loadStatus.allLoad || obj.cancelStatusId == cancelStatus.canceled){
                            canNotAccountCheckIds += obj.id + " ";
                        }
                        else{
                            canAccountCheckIds += "'" + obj.id + "',";
                        }
                    }
                }
                else{
                    for(let obj of selectItems){
                        if(obj.settlementStatusId == settlementStatus.cleared){
                            canNotAccountCheckIds += obj.id + " ";
                        }
                        else{
                            canAccountCheckIds += "'" + obj.id + "',";
                        }
                    }
                }

                if(canNotAccountCheckIds.length>0){
                    canNotAccountCheckIds = canNotAccountCheckIds.substring(0,canNotAccountCheckIds.length-1);
                    if(accountStatus == accountCheckStatus.checked){
                        showAlert("选择的对账分单【" + canNotAccountCheckIds + "】没有全部配载或已经作废，不能进行代理送货费对账确认操作!");
                    }
                    else{
                        showAlert("选择的对账分单【" + canNotAccountCheckIds + "】已结算，不能进行代理送货费对账取消操作!");
                    }
                    return;
                }

                let title = accountStatus == accountCheckStatus.checked?"确认对账?":"取消对账?";
                canAccountCheckIds = canAccountCheckIds.substring(0,canAccountCheckIds.length-1);
                // 给出确认提示框
                mini.confirm("确定为分单【" + canAccountCheckIds + "】代理送费费"+ title, "对账提示",
                    function (action) {
                        if (action == "ok") {
                            let ret = public_getServerData("${base}/pages/native_bill_manage/changeAgentDeliveryChargeAccountCheckStatus",{billIds:canAccountCheckIds,accountCheckStatusId:accountStatus});
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    grid.reload();
                                }
                            });
                        }
                    }
                );
            }


            /**
             * 对账数据上传
             */
            function showAccountPanel(accountType){


                let form_add = new mini.Form("#upload-form-add");
                form_add.clear();

                accountResult.innerHTML = "";

                // 弹出添加窗口
                public_showModelAtPos("accountPanel", "center", "middle");
            }


            function uploadAccount() {
                // 上传并对账
                let fileInput = $('#upLoadAccountFileData').get(0).files[0];
                if(fileInput){
                    mini.confirm("您确认上传代理送货费用对账数据?", "提示", function(confirmAction){
                        if(confirmAction == "ok"){
                            let messageid = mini.loading("正在上传校验及上传处理中，请稍后...","对账文件Excel上传");
                            flightAjaxFileUpload(messageid);
                        }
                    });
                }else{
                    mini.alert("没有选择要上传的对账信息数据Excel文件!");
                }

            }

            // 调用异步上传
            function flightAjaxFileUpload(messageid) {
                let formData = new FormData($("#upload-form-add")[0]);
                $.ajax({
                    //接口地址
                    url: '${base}/pages/native_bill_manage/accountFileUploadAncCheck',
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {

                        mini.hideMessageBox(messageid);

                        accountResult.innerHTML = data.message;

                        // 清空上传对象
                        clearUploadFile("upload-form-add");

                        // 重新刷新数据
                        grid.reload();

                    },
                    error: function (returndata) {
                        mini.alert("网络异常，请重试！");
                    }
                });
            }

        </script>

    </body>
</html>